﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace ServiceOperater.Converters
{
    public sealed class NumberToColorConverter : IValueConverter
    {
        private int threshold;
        #region ctor
        public NumberToColorConverter(int threshold)
        {
            this.threshold = threshold;
        }

        public NumberToColorConverter()
        {
            this.threshold = 0;
        }
        #endregion

        private static NumberToColorConverter converter;
        public static NumberToColorConverter INSTANCE
        {
            get { return converter ?? (converter = new NumberToColorConverter()); }
        }

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            int num = Int32.Parse(value.ToString());
            if (threshold.CompareTo(num) >= 0)
            {
                return System.Windows.Media.Brushes.Red;
            }
            else
            {
                return System.Windows.Media.Brushes.Black;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

}
